home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 4 / Meeting Pearls Vol. IV (1996)(GTI - Schatztruhe)[!].iso / Pearls / dev / Monitor / Snoopy / Support / buildwatch.c < prev    next >
C/C++ Source or Header  |  1993-12-18  |  6KB  |  205 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <exec/types.h>
  6. #include <dos/dos.h>
  7. #include <dos/rdargs.h>
  8. #include <clib/dos_protos.h>
  9. #include <pragmas/dos.h>
  10.  
  11. #define TEMPLATE "FILES/A/M,FDPREFIX/K,FDSUFFIX/K,RESOURCE/S,DEFSONLY/S,USEDEFS/S"
  12. #define OPT_FILES           0
  13. #define OPT_FDPREFIX        1
  14. #define OPT_FDSUFFIX        2
  15. #define OPT_RESOURCE        3
  16. #define OPT_DEFSONLY        4
  17. #define OPT_USEDEFS         5
  18. #define OPT_COUNT           6
  19.  
  20. LONG opts[OPT_COUNT];
  21.  
  22. char *ver="\0$VER: buildwatch Snoopy Support Tool 1.2 (01.01.94)";
  23. char *fdPrefix = "FD:";
  24. char *fdSuffix = "_lib.fd";
  25. extern struct Library *DOSBase;
  26.  
  27. int ParseFDFile( char *basename )
  28. {
  29.     FILE *fp;
  30.     char buffer[256];
  31.     long bias;
  32.     char *Basis = "UNKNOWN";
  33.     char fPrivate;
  34.     char fname[80];
  35.  
  36.     sprintf( fname, "%s%s%s", fdPrefix, basename, fdSuffix);
  37.  
  38.     if( ( fp = fopen( fname, "rt" ) ) == NULL )
  39.     {
  40.         printf("ERROR: cannot open %s\n", fname );
  41.         return 10;
  42.     }
  43.  
  44.     bias = 0; fPrivate = FALSE;
  45.  
  46.     printf("; Snoopy scriptfile for \"%s\"\n\n", fname );
  47.  
  48.     while( !feof( fp ) )
  49.     {
  50.         fgets( buffer, 256, fp );
  51.  
  52.         if( *buffer == '*' ) continue;
  53.  
  54.         if( *buffer == '#' && *(buffer+1) == '#' )
  55.         {
  56.             if( strnicmp( buffer+2, "bias", 4) == 0 )
  57.             {
  58.                 bias = atol( buffer + 7 ); 
  59.             }
  60.             else if( strnicmp( buffer+2, "public", 6 ) == 0 )
  61.             {
  62.                 fPrivate = FALSE;
  63.             }
  64.             else if( strnicmp( buffer+2, "private", 7 ) == 0 )
  65.             {
  66.                 fPrivate = TRUE;
  67.             }
  68.             else if( strnicmp( buffer+2, "base", 4 ) == 0 )
  69.             {
  70.                 char *cp;
  71.                 Basis = strdup( buffer+8 );
  72.                 cp = strchr( Basis, '\n' );
  73.                 if( cp ) *cp=0;
  74.                 if( !opts[OPT_DEFSONLY] )
  75.                 {
  76.                     if( opts[OPT_RESOURCE] )
  77.                     {
  78.                         printf("resource=%s,%s.resource\n",Basis,basename );
  79.                     }
  80.                     else
  81.                     {
  82.                         printf("base=%s,%s.library\n",Basis,basename );
  83.                     }
  84.                     if( opts[OPT_USEDEFS] )
  85.                     {
  86.                         printf("include=%s\n",basename);
  87.                     }                        
  88.                 }
  89.             }
  90.         }
  91.         else
  92.         {
  93.             if( !fPrivate )
  94.             {
  95.                 char *cp;
  96.                 char Regs[80];
  97.                 char *name;
  98.  
  99.                 if( ( cp = strchr( buffer, '(' ) ) != NULL )
  100.                 {
  101.                     *cp = 0;
  102.                     name = strdup( buffer );
  103.                 }
  104.                 else continue;
  105.  
  106.                 if( ( cp = strrchr( ++cp, (int)'(' ) ) != NULL )
  107.                 {
  108.                     int done = FALSE;
  109.                     int count = 0;
  110.                     int nrofregs = 0;
  111.                     
  112.                     do
  113.                     {
  114.                         switch( *cp )
  115.                         {
  116.                         case ',':
  117.                             *cp = '/';
  118.                         case '/':
  119.                             Regs[ count++ ] = 'L';
  120.                             nrofregs++;
  121.                         case 'A':
  122.                         case 'a':
  123.                         case 'D':
  124.                         case 'd':
  125.                         case '0':
  126.                         case '1':
  127.                         case '2':
  128.                         case '3':
  129.                         case '4':
  130.                         case '5':
  131.                         case '6':
  132.                         case '7':
  133.                             Regs[ count++ ] = toupper( *cp );
  134.                             break;
  135.                         case ')':
  136.                             done = TRUE;
  137.                             break;
  138.                         }
  139.                         cp++;
  140.                     }
  141.                     while( !done );
  142.                     if( count != 0 )
  143.                     {
  144.                         nrofregs++;
  145.                         Regs[ count++ ] = 'L';
  146.                         Regs[ count++ ] = '/';
  147.                     }
  148.                     Regs[ count ] = 0;
  149.                         
  150.                     strcat( Regs, "RD0L" );
  151.                     if( opts[OPT_DEFSONLY] )
  152.                     {
  153.                         printf("define=%s,-%ld\n",name,bias);
  154.                     }
  155.                     else
  156.                     {
  157.                         if( opts[OPT_USEDEFS] )
  158.                         {
  159.                             printf("watch=%s,%s,%s,%s( ", Basis, name, Regs, name );
  160.                         }                        
  161.                         else
  162.                         {
  163.                             printf("watch=%s,-%ld,%s,%s( ", Basis, bias, Regs, name );
  164.                         }
  165.                         for( ; nrofregs; nrofregs--) printf("$%%lx ");
  166.                         printf(")=$%%lx\n");
  167.                     }
  168.                 }
  169.             }
  170.             bias += 6;
  171.         }
  172.     }
  173.     fclose( fp );
  174.     return 0;
  175. }
  176.  
  177. int main(int argc, char *argv[])
  178. {
  179.     struct RDArgs *argsptr;
  180.  
  181.     if( ( argsptr = ReadArgs( TEMPLATE, opts, NULL ) ) != NULL )
  182.     {
  183.         char **sptr;
  184.  
  185.         if( opts[OPT_DEFSONLY] && (opts[OPT_USEDEFS]|opts[OPT_RESOURCE]) )
  186.         {
  187.             printf( "Sorry, DEFSONLY/S cannot appear along with USEDEFS/S or RESOURCE/S\n");
  188.         }
  189.         else
  190.         {
  191.             if( opts[OPT_FDPREFIX] ) fdPrefix = (char *)(opts[OPT_FDPREFIX]);
  192.             if( opts[OPT_FDSUFFIX] ) fdSuffix = (char *)(opts[OPT_FDSUFFIX]);
  193.             sptr = (char **)(opts[OPT_FILES]);
  194.             while( *sptr ) ParseFDFile( *(sptr++) );
  195.         }
  196.         FreeArgs( argsptr );
  197.     }
  198.     else
  199.     {
  200.         PrintFault( IoErr(), NULL );
  201.         return RETURN_ERROR;
  202.     }
  203.     return RETURN_OK;
  204. }
  205.